package ieco.daoimpl;

import ieco.domaine.Serie;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@SuppressWarnings("serial")
@Stateless
@LocalBean
public class SerieDaoImpl extends DaoImpl<String, Serie> {

	@PersistenceContext(unitName="options")
	private EntityManager entityManager;
	
	public SerieDaoImpl() {
		super(Serie.class);
	}
	
	public Serie findSerie(int id) {
		String query = "select s from Serie s where s.id = ?1";
		return find(query, id);
	}

	public int deleteSerie(int id){
		Query query = entityManager.createQuery("Delete from Serie s where s.id = ?1");
		query.setParameter(1, id);
		return query.executeUpdate();
	}
	
	public Serie findSerie(String codeSerie) {
		String query = "select s from Serie s where s.code = ?1";
		return find(query, codeSerie);
	}
	
	public List<Serie> findAllSeries(){
		String query = "select s from Serie s";
		return findAll(query);
	}
}
